<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    function Movie(name, size, time) {
      this.name = name;
      this.size = size;
      this.time = time;
    }

    let m1 = new Movie('a速度与激情10',10,'2020-10-1');
    let m2 = new Movie('b哈利波特与二美',5,'2010-5-1');
    let m3 = new Movie('c复仇者联盟4',8,'2019-4-3');
    let arr = [m1, m2, m3];

    // function sortAny(attr) {
    //   return function (obj1, obj2) {
    //     if (obj1[attr] > obj2[attr]) {
    //       return 1;
    //     }else if (obj1[attr] === obj2[attr]){
    //       return 0;
    //     }else {
    //       return -1;
    //     }
    //   };
    // }

    // let ff = sortAny('size');
    // arr.sort(ff);

    function sortAny(attr, arr) {
      function test(obj1, obj2) {
        if (obj1[attr] > obj2[attr]) {
          return 1;
        }else if (obj1[attr] === obj2[attr]){
          return 0;
        }else {
          return -1;
        }
      }
      arr.sort(test);
    }

    sortAny('time', arr);

    for (let i = 0; i < arr.length; i++) {
      console.log(arr[i].name + ': ' + arr[i].size + ': ' + arr[i].time);
    }



  </script>
</body>
</html>